//
//  ButtonAndLabels.m
//  LearnToHelp
//
//  Created by mc on 16/6/2.
//  Copyright © 2016年 Elliot. All rights reserved.
//

#import "ButtonAndLabels.h"


#define BtbAndLabelsWeith [UIScreen mainScreen].bounds.size.width/2

@implementation ButtonAndLabels

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.layer.borderWidth = 0.5;
        self.layer.borderColor = [UIColor colorWithRed:0.957 green:0.957 blue:0.961 alpha:1.000].CGColor;
        [self addButtonAndLabelsUI];
    }
    return self;
}


-(void)addButtonAndLabelsUI {
    CGFloat weith = CGRectGetWidth(self.frame);
//    cgrectma
    self.BtnImageview = [[UIImageView alloc] initWithFrame:CGRectMake((weith-(weith*11)/27)/2, (weith*6)/27, (weith*11)/27, (weith*11)/27)];
    self.BtnImageview.layer.cornerRadius = CGRectGetWidth(self.BtnImageview.frame)/2;
    self.BtnImageview.layer.masksToBounds = YES;
    self.BtnImageview.image = [UIImage imageNamed:@"kaoshi-touxiang"];
    self.BtnImageview.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.BtnImageview];
    
    self.smallImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.BtnImageview.frame)-20, CGRectGetMaxY(self.BtnImageview.frame)-20, 20, 20)];
//    self.BtnImageview.layer.cornerRadius = CGRectGetWidth(self.BtnImageview.frame)/2;
//    self.smallImageView.layer.masksToBounds = YES;
//    self.smallImageView.image = [UIImage imageNamed:@"wode-vip"];
    self.smallImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.smallImageView];
    
    
    self.FirstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.BtnImageview.frame)+(20*weith)/270, weith, (25*weith)/270)];
    self.FirstLabel.font = [UIFont systemFontOfSize:16];
    self.FirstLabel.textAlignment = NSTextAlignmentCenter;
    self.FirstLabel.textColor = [UIColor blackColor];
    [self addSubview:self.FirstLabel];
    
    
    self.SecondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.FirstLabel.frame)+(10*weith)/270, weith, (25*weith)/270)];
    self.SecondLabel.font = [UIFont systemFontOfSize:13];
    self.SecondLabel.textAlignment = NSTextAlignmentCenter;
    self.SecondLabel.textColor = [UIColor colorWithWhite:0.404 alpha:1.000];
    [self addSubview:self.SecondLabel];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
    button.tag = self.tag;
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
    
    
}
- (void)buttonClick:(UIButton *)button {
    [self.delegate buttonViewbtnClick:button];
}


@end
